{% extends 'basic_app/master.html' %}
{% block tag_left %}
    {% include 'basic_app/tag_left_user.html' %}
{% endblock %}
{% block userinfo %}
    <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
        <h2 class="page-header">添加用户页</h2>
        <form class="form-horizontal" action="{{ request.path }}" method="post" onsubmit="return validateForm()">
            <div class="form-group">
                <label class="col-sm-2 control-label">Username：</label>
                <div class="col-sm-10">
                    <input id="onsubmit_username" style="width:300px;" type="text" class="form-control" name="add_user"
                           placeholder="用户名">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Password：</label>
                <div class="col-sm-10">
                    <input id="onsubmit_passwd" type="password" style="width:300px;" class="form-control" name="add_pwd"
                           placeholder="密码">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Email：</label>
                <div class="col-sm-10">
                    <input id="onsubmit_email" style="width:300px;" type="email" class="form-control" name="add_email"
                           placeholder="邮箱">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Phone_number：</label>
                <div class="col-sm-10">
                    <input id="onsubmit_phone" style="width:300px;" type="text" class="form-control" name="add_phone"
                           placeholder="手机号">
                </div>
            </div>
                        <div class="form-group">
                <label class="col-sm-2 control-label">status：</label>
                <div class="col-sm-10">
                    <input  style="width:300px;" type="text" class="form-control" name="add_status"
                           placeholder="状态">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-2 control-label">Dept：</label>
                <div class="col-sm-10">
                    <select class="form-control" style="width:300px;" name="add_dept">
                        <option>DBA</option>
                        <option>Dev</option>
                    </select>
                </div>
            </div>
            <div class="col-sm-10">
                {#                <button type="submit" class="btn">提交</button>#}
                <div style="text-align:center;vertical-align:middle;"><input type="submit" class="btn" value="提交"></div>
                {# <button type="button" class="btn" onclick="check(this.form)">提交</button>#}
                {#                <input type="button" class="btn" onclick="return check(this.form)" value="提交" name="submit1">#}
            </div>
        </form>
    </div>
{% endblock %}
{% block script %}
    <script>
        function validateForm() {
            console.log("1111")
            var phone_reg = /^1[3|4|5|7|8]\d{9}$/;
            var memberPass = /^[a-zA-Z0-9_]{6,20}$/;
            var numPass = /^[0-9]+$/;
            var dPass = /^[a-zA-Z]+$/
            var username = document.getElementById("onsubmit_username");
            var password = document.getElementById("onsubmit_passwd");
            var phone = document.getElementById("onsubmit_phone");
            if (username.value == '' || username.value == null) {
                alert("请输入用户名");
                return false;
            }
            if (password.value == '' || password.value == null) {
                alert("请输入密码");
                password.focus();
                return false;
            }
            if (!memberPass.test(password.value)) {
                alert("密码格式不正确、格式要求:6-20位,数字+字母组合");
                password.focus();
                return false;
            }
            if (numPass.test(password.value)) {
                alert("密码格式不正确、密码不能为纯数字");
                password.focus();
                return false;
            }
            if (dPass.test(password.value)) {
                alert("密码格式不正确、密码不能为纯字母");
                password.focus();
                return false;
            }
            if (phone.value=='' || phone.value == null || !phone_reg.test(phone.value)) {
                alert("请输入正确的手机号");
                password.focus();
                return false;
            }
            return true;
        }
    </script>
{% endblock %}
